package thread;

public class Demo03 {
    public static void main(String[] args) {
        //匿名对象重写run()方法创建线程对象
        //继承 Thread, 重写 run, 使用匿名内部类
        Thread t = new Thread(){
            //线程执行的任务
            @Override
            public void run() {
                while(true){
                    System.out.println("hello thread");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        //启动线程（在操作系统中创建线程）
        t.start();

        //主线程执行的任务
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
